import {
	quotation_new
} from '@/api/index.js'

const state = {
	currencyList: [],
	currencyShowList: []
}

const mutations = {
	SET_CURRENCYLIST: (state, currencyList) => {
		state.currencyList = currencyList
	},
	SET_CURRENCYSHOWLIST: (state, currencyShowList) => {
		state.currencyShowList = currencyShowList
	},
}

const actions = {
	// get wallet list
	getCurrencyList({
		commit
	}) {
		return new Promise((resolve, reject) => {
			quotation_new().then(response => {
				if (response.error) return reject();
				let arry = [], data = response.res;
				commit('SET_CURRENCYSHOWLIST', data)
				for (let i in data) {
					let obj = {
						title: data[i].name,
						id: data[i].id,
						rate: data[i].rate
					}
					arry.push(obj)
				}
				commit('SET_CURRENCYLIST', arry || [])
				resolve(data)
			})
		})
	}
}

export default {
	namespaced: true,
	state,
	mutations,
	actions
}
